package com.guarantee.server.service.impl;

import com.guarantee.server.common.base.BaseServiceImpl;
import com.guarantee.server.domain.Rule;
import com.guarantee.server.domain.Store;
import com.guarantee.server.mapper.RuleMapper;
import com.guarantee.server.mapper.StoreMapper;
import com.guarantee.server.service.IRuleService;
import com.guarantee.server.service.IStoreService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Author huisonglin
 * @Description
 * @PackageName autofood-rest
 * @Package com.guarantee.server.service.impl
 * @Date 2024-07-12 13:11
 * @Version 1.0
 */
@Service
public class RuleServiceImpl extends BaseServiceImpl<RuleMapper, Rule> implements IRuleService {
    @Override
    public Integer getTime(Long ruleId, String orderPirce) {
        Integer excuteTime = getExcuteTime(ruleId, orderPirce);
        if(excuteTime == null){
            return this.selectById(ruleId).getTime();
        }else{
            return excuteTime;
        }
    }

    public Integer getExcuteTime(Long ruleId, String orderPirce){
        Rule rule = this.selectById(ruleId);

        if(StringUtils.isBlank(orderPirce)){
            return rule.getTime();
        }
        BigDecimal bigDecimal = new BigDecimal(orderPirce);
        if(bigDecimal.compareTo(new BigDecimal("50")) == -1){
            return rule.getTime();
        }
        if(bigDecimal.compareTo(new BigDecimal("100")) ==  -1){
            return rule.getMidOrderTime();
        }else{
            return rule.getMaxOrderTime();
        }

    }

}
